package com.sunsheng.modules.juc;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ThreadPollDemo {
    public static void main(String[] args) {
        //创建一池5线程
//        ExecutorService executor = Executors.newFixedThreadPool(5);
        //创建一池一线程
//        ExecutorService executor = Executors.newSingleThreadExecutor();
        //创建自动扩容线程池
        ExecutorService executor = Executors.newCachedThreadPool();
        try {
            for (int i = 0; i < 20; i++) {
                executor.execute(() -> {
                    System.out.println("当前是" + Thread.currentThread().getName() + "线程在处理");
                });
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            executor.shutdown();
        }
    }
}
